# Name: JoinXY.py - MCBS 06/12/2015
# Description: Joins X and Y coordinates to table

# import system module
import arcpy
from arcpy import env
#from arcpy.sa import *


# Set workspace environment:
#env.workspace = "CanasatData.gdb"
env.workspace = "C:\Users\Marcelo\Documents\Sugarcane\Offline Data\MunicBasedData\CanasatData.gdb"
env.overwriteOutput = True
#arcpy.CheckOutExtension("Spatial")

# Folder to store tables:
PathForTables = "C:\Users\Marcelo\Documents\Sugarcane\Offline Data\MunicBasedData\Tables"

# Input grid:
GridName      = "G1kmMiR"
# Output grids name:
OutName       = "G1kmMiRXY"

# Copying data to preserve original dataset
# Execute Copy
arcpy.Copy_management(GridName, OutName)
# Execute AddXY
arcpy.AddXY_management(OutName)

# Save .dbf tables in specified folder
TableName    = OutName + ".dbf"
arcpy.TableToTable_conversion(OutName, PathForTables, TableName)

